home *** CD-ROM | disk | FTP | other *** search
/ Languguage OS 2 / Languguage OS II Version 10-94 (Knowledge Media)(1994).ISO / gnu / glibc108.zip / glibc108 / malloc / mem-limits.h < prev    next >
C/C++ Source or Header  |  1994-04-19  |  4KB  |  172 lines

  1. /* Includes for memory limit warnings.
  2.    Copyright (C) 1990, 1993, 1994 Free Software Foundation, Inc.
  3.  
  4.  
  5. This file is part of the GNU C Library.  Its master source is NOT part of
  6. the C library, however.  The master source lives in /gd/gnu/lib.
  7.  
  8. The GNU C Library is free software; you can redistribute it and/or
  9. modify it under the terms of the GNU Library General Public License as
  10. published by the Free Software Foundation; either version 2 of the
  11. License, or (at your option) any later version.
  12.  
  13. The GNU C Library is distributed in the hope that it will be useful,
  14. but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  16. Library General Public License for more details.
  17.  
  18. You should have received a copy of the GNU Library General Public
  19. License along with the GNU C Library; see the file COPYING.LIB.  If
  20. not, write to the Free Software Foundation, Inc., 675 Mass Ave,
  21. Cambridge, MA 02139, USA.  */
  22.  
  23. #ifdef MSDOS
  24. #include <dpmi.h>
  25. #endif
  26.  
  27. /* Some systems need this before <sys/resource.h>.  */
  28. #include <sys/types.h>
  29.  
  30. #ifdef _LIBC
  31.  
  32. #include <sys/resource.h>
  33. #define BSD4_2            /* Tell code below to use getrlimit.  */
  34.  
  35. #else
  36.  
  37. #if defined (__osf__) && (defined (__mips) || defined (mips))
  38. #include <sys/time.h>
  39. #include <sys/resource.h>
  40. #endif
  41.  
  42. #ifdef __bsdi__
  43. #define BSD4_2
  44. #endif
  45.  
  46. #ifndef BSD4_2
  47. #ifndef USG
  48. #ifndef MSDOS
  49. #include <sys/vlimit.h>
  50. #endif /* not MSDOS */
  51. #endif /* not USG */
  52. #else /* if BSD4_2 */
  53. #include <sys/time.h>
  54. #include <sys/resource.h>
  55. #endif /* BSD4_2 */
  56.  
  57. #endif /* _LIBC */
  58.  
  59. #ifdef emacs
  60. /* The important properties of this type are that 1) it's a pointer, and
  61.    2) arithmetic on it should work as if the size of the object pointed
  62.    to has a size of 1.  */
  63. #ifdef __STDC__
  64. typedef void *POINTER;
  65. #else
  66. typedef char *POINTER;
  67. #endif
  68.  
  69. typedef unsigned long SIZE;
  70.  
  71. #ifdef NULL
  72. #undef NULL
  73. #endif
  74. #define NULL ((POINTER) 0)
  75.  
  76. extern POINTER start_of_data ();
  77. #ifdef DATA_SEG_BITS
  78. #define EXCEEDS_LISP_PTR(ptr) \
  79.   (((unsigned int) (ptr) & ~DATA_SEG_BITS) >> VALBITS)
  80. #else
  81. #define EXCEEDS_LISP_PTR(ptr) ((unsigned int) (ptr) >> VALBITS)
  82. #endif
  83.  
  84. #ifdef BSD
  85. #ifndef DATA_SEG_BITS
  86. extern char etext;
  87. #define start_of_data() &etext
  88. #endif
  89. #endif
  90.  
  91. #else  /* Not emacs */ 
  92. extern char etext;
  93. #define start_of_data() &etext
  94. #endif /* Not emacs */
  95.  
  96.   
  97.  
  98. /* start of data space; can be changed by calling malloc_init */
  99. static POINTER data_space_start;
  100.  
  101. /* Number of bytes of writable memory we can expect to be able to get */
  102. static unsigned int lim_data;
  103.  
  104. #ifdef NO_LIM_DATA
  105. static void
  106. get_lim_data ()
  107. {
  108.   lim_data = -1;
  109. }
  110. #else /* not NO_LIM_DATA */
  111.  
  112. #ifdef USG
  113.  
  114. static void
  115. get_lim_data ()
  116. {
  117.   extern long ulimit ();
  118.  
  119.   lim_data = -1;
  120.  
  121.   /* Use the ulimit call, if we seem to have it.  */
  122. #if !defined (ULIMIT_BREAK_VALUE) || defined (LINUX)
  123.   lim_data = ulimit (3, 0);
  124. #endif
  125.  
  126.   /* If that didn't work, just use the macro's value.  */
  127. #ifdef ULIMIT_BREAK_VALUE
  128.   if (lim_data == -1)
  129.     lim_data = ULIMIT_BREAK_VALUE;
  130. #endif
  131.  
  132.   lim_data -= (long) data_space_start;
  133. }
  134.  
  135. #else /* not USG */
  136. #if !defined (BSD4_2) && !defined (__osf__)
  137.  
  138. #ifdef MSDOS
  139. void
  140. get_lim_data ()
  141. {
  142.   _go32_dpmi_meminfo info;
  143.  
  144.   _go32_dpmi_get_free_memory_information (&info);
  145.   lim_data = info.available_memory;
  146. }
  147. #else /* not MSDOS */
  148. static void
  149. get_lim_data ()
  150. {
  151.   lim_data = vlimit (LIM_DATA, -1);
  152. }
  153. #endif /* not MSDOS */
  154.  
  155. #else /* BSD4_2 */
  156.  
  157. static void
  158. get_lim_data ()
  159. {
  160.   struct rlimit XXrlimit;
  161.  
  162.   getrlimit (RLIMIT_DATA, &XXrlimit);
  163. #ifdef RLIM_INFINITY
  164.   lim_data = XXrlimit.rlim_cur & RLIM_INFINITY; /* soft limit */
  165. #else
  166.   lim_data = XXrlimit.rlim_cur;    /* soft limit */
  167. #endif
  168. }
  169. #endif /* BSD4_2 */
  170. #endif /* not USG */
  171. #endif /* not NO_LIM_DATA */
  172.